package models

type TerminalCar struct {
	Id           int64  `xorm:"not null pk autoincr INT(11)"`
	TerminalId   int64  `xorm:"not null comment('终端编号') unique INT(11)"`
	CarId        int64  `xorm:"not null comment('教练车编号') unique INT(11)"`
	Sim          string `xorm:"not null comment('终端SIM卡号') unique VARCHAR(16)"`
	RecordStatus string `xorm:"default '1' comment('1:已绑定2 解绑定') ENUM('1','2')"`
	Reged        string `xorm:"not null default '0' comment('设备是否鉴权 0未鉴权 1 已鉴权') ENUM('0','1')"`
	Remark       string `xorm:"VARCHAR(255)"`
	Iswuhan      string `xorm:"ENUM('0','1')"`
}

func (t *TerminalCar) GetTerCarInfoByTerSim(sim string) (has bool, car TerminalCar, err error) {
	has, err = engine.Table("dts_terminal_car").Where("sim=?", sim).Get(&car)
	return has, car, err
}

func (t *TerminalCar) GetOneTerminalCarByTerminalId(id interface{}) (list TerminalCar, err error) {
	temp := new(TerminalCar)
	_, err = engine.Table("dts_terminal_car").
		Where("terminal_id = ?", id).
		Get(temp)
	return *temp, err
}

func (t *TerminalCar) Delete() bool {
	terminalCar := new(TerminalCar)
	terminalCar.Id = t.Id
	_, err := engine.ID(t.Id).Delete(terminalCar)
	if err != nil {
		return false
	}
	return true
}
